package com.neusmart.common.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.neusmart.common.R;
import com.neusmart.common.util.MToast;
import com.neusmart.common.view.slidingmenu.SlidingFragmentActivity;
import com.neusmart.common.view.slidingmenu.SlidingMenu;

/**
 * Sliding BaseActivity
 * <p/>
 * keven
 */
public class SlidingBaseActivity extends SlidingFragmentActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // set the Behind View
        setBehindContentView(R.layout.menu_frame);//设置菜单的布局
        // customize the SlidingMenu
        SlidingMenu sm = getSlidingMenu();//初始化Slidemenu：
        sm.setShadowWidthRes(R.dimen.shadow_width);//阴影宽度
        sm.setShadowDrawable(R.drawable.shadow);//阴影Drawable
        sm.setBehindOffsetRes(R.dimen.x128);//拉开后离边框距离
        sm.setFadeEnabled(true);//是否有渐变
        sm.setFadeDegree(0.35f);//设置渐变比率
      //  sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN );//边缘模式，在正文布局的边缘处通过手势可以找开SlidingMenu
      //  sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);//自然是不能通过手势打开SlidingMenu了
        sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);//全屏滑动
       // sm.setTouchModeBehind(SlidingMenu.TOUCHMODE_MARGIN);

        sm.setMode(SlidingMenu.LEFT);//菜单左边显示
        setContentView(R.layout.content_frame);
    }

    protected void setMenu(Fragment fragment) {
        setFragment(R.id.menu_frame, fragment);
    }

    protected void setContent(Fragment fragment) {
        setFragment(R.id.content_frame, fragment);
    }

    public void setFragment(int resId, Fragment fragment) {
        getSupportFragmentManager().beginTransaction().replace(resId, fragment)
                .commitAllowingStateLoss();
    }

    public void showToast(int resId) {
        MToast.showText(this, resId);
    }

    public void showToast(String msg) {
        MToast.showText(this, msg);
    }
}
